#ifndef __NETWORK_CONNECTOR_H__
#define __NETWORK_CONNECTOR_H__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

#include "../Settings/Settings.h"
#include "Connector.h"
#include "StringParser.h"
#include "CommandMaker.h"

class NetworkConnector: public Connector
{
private:
  struct sockaddr_in serv_addr;
  //struct hostent *server;
  
  Settings &settings_;
  StringParser parser;
  CommandMaker cmaker;
  int confirmedSeat;
  
  static const int BUFFER_LENGTH;

  int sockfd;
  int portNum;

  char buffer[1024];
  fd_set readset;    

  int sendMessageToServer(const std::string &message);
  int getMessage();
  bool connected;
  void zeroBuffer();


public:

  NetworkConnector();
  ~NetworkConnector();
  //some of players opens card
  int openCard(int playerNum);

  //some of players gets totem
  int getTotem(int playerNum);

  int connectToServer(const std::string &serverAddr);

  int connect(const std::string &name, const time_t &connectTime, int &error);
  
  int getPlayersFromServer();


  int getConfirmedSeat();
  
  char getMove(bool &toExit);

   void quit(int playerNum);

 
  void disconnect();
};

#endif
